package components.custom
{
	import flash.events.Event;
	
	import framework.LangMgr;

	public class CheckBoxColumnHeaderRenderer extends CenterAlignCheckBox
	{
		public static const ADD_HEADER:String = "addHeader";
		public static const SELECTED_OR_UNSELECTED_ALL:String = "selectedOrUnselectedAll";
		
		public function CheckBoxColumnHeaderRenderer()
		{
			super();
			locale = "checkbox.selectAll";
			addEventListener(Event.ADDED_TO_STAGE, addToStageHandler);
			addEventListener(Event.CHANGE, changeHandler); 
		}
		
		/**附带数据**/
		override public function set data(p_obj:Object):void
		{
			super.data = p_obj;
			if(p_obj is String || p_obj is Number)
				toolTip = String(p_obj);
		}
		
		private function addToStageHandler(p_evt:Event):void
		{
			selected = false;
			dispatchEvent(new Event(ADD_HEADER, true));
		}
		
		private function changeHandler(event:Event):void
		{
			if(selected)
				locale="checkbox.deSelectAll";
			else
				locale="checkbox.selectAll";
			dispatchEvent(new Event(SELECTED_OR_UNSELECTED_ALL, true));
		}
		
		/**
		 * 实现国际化
		 */
		override protected function resourcesChanged():void
		{
			super.resourcesChanged();
			if(locale){
				label = "";
				toolTip = LangMgr.getResourceByLocaleKey(locale);
			}
		}
		
		override public function dispose():void
		{
			removeEventListener(Event.ADDED_TO_STAGE, addToStageHandler);
			removeEventListener(Event.CHANGE, changeHandler); 
		}
	}
}